﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Domain.PermisosModule.Contracts.Ciclos;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.DistributedServices.PermisosModule.Resources;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public List<Ciclo> FindAllCiclos()
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				return cicloService.FindAllCiclos();
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Ciclo> FindCiclosByStatus(bool status = true)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				return cicloService.FindCiclosByStatus(status);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cicloGuid"></param>
		/// <returns></returns>
		public Ciclo FindCicloByGuid(Guid cicloGuid)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				return cicloService.FindCicloByGuid(cicloGuid);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ciclo"></param>
		public void MakeCicloActual(Ciclo ciclo)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				cicloService.MakeCicloActual(ciclo);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ciclo"></param>
		public void AddCiclo(Ciclo ciclo)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				cicloService.AddCiclo(ciclo);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ciclo"></param>
		public void ChangeCiclo(Ciclo ciclo)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				cicloService.ChangeCiclo(ciclo);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ciclo"></param>
		public void DeleteCiclo(Ciclo ciclo)
		{
			try
			{
				ICicloService cicloService = IoCFactory.Resolve<ICicloService>();
				cicloService.DeleteCiclo(ciclo);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
